import APIgetHospitalList from "../../assets/js/hospital-list.js";
import {
  formatTime
} from "../../utils/util.js"

Page({
  data: {
    noList: {
      img: "/assets/img/zwjl.png",
      text: "暂无可选医院"
    },
    hospitalList: [
      // {
      //   id: 1,
      //   img: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=156585113304d5&di=c8607ffc4906f6b9cca1eb5ca8ee2f08&imgtype=0&src=http%3A%2F%2Fb.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F908fa0ec08fa513db777cf78376d55fbb3fbd9b3.jpg",
      //   title: "a医院",
      //   time: "2019/03/02",
      //   address: "什么什么地方"
      // },
      // {
      //   id: 2,
      //   img: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1565851133045&di=c8607ffc4906f6b9cca1eb5ca8ee2f08&imgtype=0&src=http%3A%2F%2Fb.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F908fa0ec08fa513db777cf78376d55fbb3fbd9b3.jpg",
      //   title: "b医院",
      //   time: "2019/03/02",
      //   address: "什么什么地方"
      // }
    ]
  },
  onLoad: function(options) {},
  onReady: function() {},
  onShow: function() {
    this.getHospitalList();
  },
  // 获取医院列表
  getHospitalList: function() {
    APIgetHospitalList({
      page: 1,
      pageSize: 1000,
    }).then(res => {
      let hospitalList = [];
      if (res.records.length) {
        res.records.forEach((item, index) => {
          let obj = item;
          obj.id = item.hospitalId; // 每家医院的唯一标识
          obj.img = item.logo || "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=156585113304d5&di=c8607ffc4906f6b9cca1eb5ca8ee2f08&imgtype=0&src=http%3A%2F%2Fb.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F908fa0ec08fa513db777cf78376d55fbb3fbd9b3.jpg"; //每家医院的图片
          obj.title = item.name; // 每家医院的名字
          obj.address = `${item.province}${item.city}${item.county}${item.address}` || "浙江省杭州市物联网街"; // 每家医院的地理位置
          let text = ""
          if (item.hospitalServiceItems.length) {
            item.hospitalServiceItems.forEach(item1 => {
              text += `${item1.name}、`
            })
            text = text.slice(0, text.length - 1)
          } else {
            text = "暂无服务"
          }
          obj.time = `特殊服务：${text}`
          hospitalList.push(obj);
        });
      } else {
        hospitalList = [];
      }
      this.setData({
        hospitalList
      })
    })
  },
  // 点击其中一家医院做的事
  handleClickOne: function(e) {
    let obj = e.detail;
    let item = obj.item;
    let index = obj.index;
    wx.navigateTo({
      url: `/pages/u_serviceItemList/u_serviceItemList?hospitalId=${item.id}&title=${item.title}` //医院的唯一标识带上获取  调接口时修改回来
      // url: `/pages/u_serviceItemList/u_serviceItemList?hospitalId=1&title=浙江省人民医院` //医院的唯一标识带上获取
    })
  }
})